pp108 : Compensate Event

Compensate Event

This topic describes a Compensate event.

Since BPMN is mostly used for the orchestration of heterogeneous Web services and Asynchronous activities which are long running, the well known ACID transaction is not always a possibility. (However Process Platform supports ACID transaction for WS-AppServer based activities). So to maintain the integrity of the business, BPMN has introduced the concept of compensation. According to this concept, when we're not able to roll back an already performed activity, we can compensate that activity with another activity that can counter the previous action. In the well known example of electronic money transfer, money credited to your account can be rolled back by debiting the same amount to your account.

A Compensate event is a BPMN construct, which reverses or rolls back the effects of an operation that has been executed. A Compensate event is triggered when an error is encountered during a process. Compensate event rolls back the actions prior to the occurence of the error. A Compensate event occurs outside the normal flow of the business process, and is triggered based on the rollback of a transaction. A Compensate event can be defined for an Activity, Sub-process, For Each, While, Until, and Context BPMN constructs. However, an Activity or Sub-process cannot have more than one Compensate event. Compensate event is graphically represented as follows: .

Use case

Let us take an example of a Conference Management portal. This portal takes care of your travel itinerary, accommodation and conference hall booking for conducting conferences in any major cities of Western Europe.

In this example, the business process is pretty simple. The customer provides his/her travel plan and preferred mode of travel. Once the train or flight tickets are booked, the customer is provided with a list of hotels to choose from. Once he/she selects a hotel, the guest room and the conference room are booked and simultaneously, the press conference for that event is arranged. Once all these bookings are done, the customer has to make the payment. When the payment is made, the itinerary is sent to the customer.

In the booking sub process, you will find that there are four web service operations and a task. The task is just a read operation, which provides a list of hotels to select. But the web services perform update operations and they belong to different systems across the network. So, here it not possible to define an ACID transaction for these kind of operations. When all these operations in the above process work fine, there will not be any integrity problem. The problems may arise only when

  • The user has select to travel by train, the train ticket is booked and when the process tries to book the hotel, the hotel booking service is not available or the network connection is down?
  • The hotel booking is also done but the press conference request fails?
  • It is normal in travel industry to block until the customer pays to make it a confirmed booking. If the customer doesn't respond within the prescribed time limit then, the booking is cancelled
  • So, here if the customer doesn't make payment in three days, all the books stand cancelled/released.

Solution proposal

To satisfy all the above requirements, we have to introduce compensating activities in the above business process. When we associate compensating activities to the update operation in the above process, this is how the process looks like:

In the above model, each operation that can modify the state is associated with an compensating activity which nullifies the change that is done by its counterpart. Cancel TrainTkt activity deletes the booking performed by the Book Train activity. The activity Select Hotel in the above model is not associated with any compensating activity because this is just a read operation.

When process instance executes an activity, it checks for the availability of compensating activity for that operation. If the operation exists, the compensating activity is put into a stack. This stack piles up as the process execution continues. In the above case, if the user selects train as the mode of transport, then Book Train activity will be executed and Cancel TrainTkt activity will be put into the compensation stack. Since the Book Flight activity is not executed, the Cancel FlightTkt activity will not be added to the compensation stack.

To execute the compensation activities, the process should end with roll back. When the process ends with a rollback, the process instance pops up the activities one after another from the compensation stack and executes the same. In the above model, we have to define an exception handler for the Booking sub-process, to ensure that in case of failure in that context, the customer is notified about the error and the process ends with a rollback. This ensures the all the activities that are performed till then are compensated. Let us assume that the process has booked the train ticket and the hotel, in which case, the compensation stack will have Cancel Hotel and Cancel TrainTkt activities. If the Arrange Press Conference fails, these two compensating activities will undo the train and hotel bookings.

We have defined a timeout of three days for the payment activity, within which time if the customer doesn't pay, all the booking will be reverted via compensation.

Related tasks

Setting the Properties of a Compensate Event
Modeling a Transaction
Setting the Properties of a Transaction